<template>
  <div class="hello">
    <h2>角色注册</h2>
    用户名：<input type="text" v-model="name"><br><br>
    <button @click="zhu">注册</button>
  </div>
</template>

<script>
export default {
  name: 'Regin',
  data () {
    return {
        name:'',
    }
  },
  methods:{
      zhu:function(){
          if(!this.name){
               alert("用户名不能为空！");
               return false;
           }
          let formdata = new FormData();
          formdata.append('name',this.name);
          this.axios({
              url:'http://127.0.0.1:8000/app01/role/',
              method:'post',
              data:formdata
          }).then(res=>{
              if (res.data.code==200){
                  alert('注册成功！')
                  this.$router.push({
                    name: 'Regin'
                  })
              }else{
                  alert(res.data.msg)
              }
        })
      }
  }
}
</script>